<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>评教系统</title>

<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="js/layui/css/layui.css"/>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/vector.js"></script>
<script src="js/login.js" type="text/javascript" charset="utf-8"></script>

<script src="js/layer/layer.js" type="text/javascript" charset="utf-8"></script>

</head>
<body>

<div id="container">
	<div id="output">
		<div class="containerT">
			<h1>用户登录</h1>
			<form class="form" id="entry_form">
				<input type="text" placeholder="用户名" id="entry_name" value="admin">
				<input type="password" placeholder="密码" id="entry_password">
				<button type="button" id="entry_btn">登录</button>
				<div id="prompt" class="prompt"></div>
			</form>
		</div>
	</div>
</div>

<script type="text/javascript">
    $(function(){
        Victor("container", "output");   //登录背景函数
        $("#entry_name").focus();
        $(document).keydown(function(event){
            if(event.keyCode==13){
                $("#entry_btn").click();
            }
        });
		
		
		$("#entry_btn").click(function(){
		var entry_name=$("#entry_name").val();
		var entry_password=$("#entry_password").val();
		  if(entry_name==""){
			  
			layer.msg("用户名不能为空", {time:1000, icon:5, shift:6},function(){
				
			});
			return;
			}
			  if(entry_password==""){
				  layer.msg("用户密码不能为空", {time:1000, icon:5, shift:6},function(){
					  return ;
				  });
				  return;
			  } 
		
		
		var data={
			  "username": entry_name,
			  "password":entry_password
		}
			$.ajax({       
						   type:"post",
						   url:"http://127.0.0.1:8080/user/login",
						   dataType: 'json',
		                  contentType: "application/json;charset=utf-8",
						   
						data: JSON.stringify(data),
							
						 success:function(ms){
					
		                            
									if(ms.result=1){
									/* 	alert("登陆成功") */
										/* $(location).prop('href', 'Student.html') */
										 if(ms.user.teacherid!=null){
										window.location.href ="Teacher.html?userid="+ms.user.userid;
										window.localStorage["token"]=ms.token;
										 }else if(ms.user.studentid!=null){
											 window.location.href = "Student.html?userid="+ms.user.userid;
											 window.localStorage["token"]=ms.token;
										 }else if(ms.user.teacherid==null&&ms.user.studentid==null){
											 window.location.href = "Sys.html?userid="+ms.user.userid;
											 window.localStorage["token"]=ms.token;
											 
										 }
									}else{
										alert(ms.message);
									}
						 },
						 error:function(d){
							 
							 alert("出现了未知错误");
						 }
					})
		
		
		
			})
		
    });
</script>

</body>
</html>